Repository navigation
Use zig assert for apicheck - #213
Conversation
|
It's looking like it might not be possible to get this working in Lua 5.5 currently. Other versions of Lua work like this:
Lua 5.5 removed I tried patching the lapi.h header file to remove those definitions, but since headers are searched for in directories I couldn't find a way to exclude the original unpatched lapi.h. Maybe copy all of the other headers and the patched header to a new directory? I'm considering posting on the Lua mailing list about this change in behavior in Lua 5.5 and see what comes up |
|
@natecraddock looking through the source, I suspect one can do #undefine LUA_USE_APICHECK
#define api_check(l,e,msg) zlua_assert(l,e,msg)hmmm... apparently not... |
|
I looked into this some more, and I also cannot redefine |
|
Yeah, I think it's worth merging! |
28fe616 to
f05e7fc
Compare
For Lua 5.1, 5.2, 5.3, 5.4, and 5.5, this configures the Lua "api check" to use Zig's std.debug.assert() instead of C's assert() from <assert.h>. This includes stack traces which makes the assert a million times more helpful. LuaJIT does not use assert() so this does not work for LuaJIT, but this commit does enable basic api check support for LuaJIT. Enables these stack trace assertions by default. Users can opt-out by setting apicheck_type to .default when adding ziglua as a dependency.
f05e7fc to
9c4c564
Compare
|
@robbielyman I got this working in Lua 5.5! And the implementation is overall much simpler. See the updated description if you are curious Feel free to take a look. I'll probably merge this in about a day. |
|
Oh, very nice solution! Good work 😁 |
Using a zig assert for apicheck enables stack traces for panics. This works by adding an
assert.himplementation that Lua will find when searching for<assert.h>that calls a Zig assert function (with stack trace) instead of C's assert().Before
After
This works for Lua 5.1 through 5.5. LuaJIT is not supported. This PR does enable basic apicheck support for LuaJIT though.
Luau seems to always do apicheck with a stack trace, so this has no impact on Luau.
If for some reason this causes issues, users can opt-out by setting apicheck_type = .basic when adding the dependency